// view/my/zzhgl/zzhgl.js
let app = getApp()
let yuming = app.globalData.yuming
const request = require('../../config/request');
Page({
  /**
   * 页面的初始数据
   */
  ...request,
  data: {
    yuming: yuming,
    heights: '',
    title: "子账号",
    list: []
  },
  // 删除
  shan(e) {
    var id = e.currentTarget.dataset.id
    var that = this
    wx.showModal({
      title: '您确定要删除吗？',
      cancelText: '取消',
      confirmText: '确定',
      success: function (res) {
        if (res.confirm) {
          console.log("确定")
          that.dele(id)
        } else {
          console.log("取消")
        }
      }
    })
  },
  // 删除接口
  dele(id) {
    let that = this
    this.myRequest(yuming + 'shop/ShopDelSubSon', {
      shopId: wx.getStorageSync('shopId'),
      id: id
    }, 'POST').then(res => {
      wx.showToast({
        title: res.data.msg,
        icon: 'none'
      })
      if (res.data.code == 200) {
        that.list()
      }
    })
  },
  // 列表
  list() {
    var that = this
    wx.showLoading({
      title: '加载中',
      icon: 'none'
    })
    this.myRequest(yuming + 'shop/ShopSelectSubSon', {
      shopId: wx.getStorageSync('shopId')
    }, 'POST').then(res => {
      wx.hideLoading();
      if (res.data.code == 200) {
        that.setData({
          list: res.data.data
        })
      }
    })
  },
  // 添加
  jias() {
    wx.navigateTo({
      url: '/my_other/addzzhgl/addzzhgl?title=添加&state=0',
    })
  },
  // 编辑
  bianji(e) {
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/my_other/addzzhgl/addzzhgl?title=修改&state=1&id=' + id,
    })
  },
  backs() {
    wx.navigateBack({
      delta: 1
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      heights: wx.getMenuButtonBoundingClientRect().top + 5,
      title: options.title
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.list()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
})